#ifndef VSVIEWFAMILY_H
#define VSVIEWFAMILY_H
#include "VSSystem.h"
#include "VSReference.h"
#include "VSCamera.h"
#include "VSSceneRender.h"
namespace VSEngine2
{
	DECLARE_Proxy(VSPostEffectSet);
	class VSGRAPHIC_API VSViewFamily
	{
	public:
		
		VSViewFamily(const VSString &ViewFamilyName,VSCamera * pCamera,VSPostEffectSetRPtr pPostEffectSet,bool bDrawDebugInfo = true,bool bBeforePostDebugDraw = true);
		virtual ~VSViewFamily();
		inline void AddScene(VSScene* pScene);
		inline VSScene * GetScene(unsigned int i)const;
		inline void ClearAllScene();
		inline void DeleteScene(unsigned int i);
		inline void DeleteScene(VSScene * pScene);
		inline unsigned int GetSceneNum()const;
		virtual void Draw(double dAppTime) = 0;
		void Update(double dAppTime);
		VSDebugDraw * GetDebugDraw(unsigned int uiRenderGroup);
		void SetUseState(VSRenderState & RenderState,unsigned int uiRenderStateInheritFlag);
		void ClearUseState();
		VSSceneRender * GetMaterialSceneRender()const
		{
			return m_pMaterialSceneRenderder;
		}
		enum //RenderTargetBuffer
		{
			RTB_COLOR = 0,
			RTB_COLOR_LEFT= 0,
			RTB_COLOR_RIGHT = 1,
			RTB_COLOR_TOP = 2,
			RTB_COLOR_BOTTOM = 3,
			RTB_COLOR_FRONT = 4,
			RTB_COLOR_BACK = 5,
			RTB_NORMALDEPTH = 6,
			RTB_MAX
		};
		virtual void CreateRenderTargetBuffer(unsigned int uiWidth,unsigned int uiHeight);
		bool IsReCreate(unsigned int uiWidth,unsigned int uiHeight);
		VSRenderTarget * GetFinalColorRT();

		VSString m_ViewFamilyName;
		bool m_bEnable;
	protected:
		VSCamera* m_pCamera;
		VSMaterialSceneRenderPtr m_pMaterialSceneRenderder;
		VSDebugDrawSceneRenderPtr m_pDebugDrawSceneRender;
		VSNormalDepthSceneRenderPtr m_pNormalDepthSceneRender;
		VSPostEffectSetRPtr m_pPostEffectSet;
		VSArray<VSScene *> m_pScene;
		VSCuller	m_Culler;
		VSRenderTargetPtr m_pRenderTargetBuffer[RTB_MAX];
		VSDepthStencilPtr m_pDepthStencil[VSCuller::RG_MAX];
		
	protected:
		unsigned int m_uiWidth;
		unsigned int m_uiHeight;	
		bool m_bBeforePostDebugDraw;
	};

	inline void VSViewFamily::AddScene(VSScene * pSecen)
	{
		if(pSecen)
		{
			for (unsigned int i = 0 ; i < m_pScene.GetNum() ;i++)
			{
				if (m_pScene[i] == pSecen)
				{
					return ;
				}
			}
			m_pScene.AddElement(pSecen);
		}
	}
	inline VSScene * VSViewFamily::GetScene(unsigned int i)const
	{
		if(i >= m_pScene.GetNum())
			return NULL;
		return m_pScene[i];
	}
	inline void VSViewFamily::ClearAllScene()
	{
		m_pScene.Clear();
	}
	inline void VSViewFamily::DeleteScene(unsigned int i)
	{	
		if(i >= m_pScene.GetNum())
			return ;
		m_pScene.Erase(i);

	}
	inline void VSViewFamily::DeleteScene(VSScene * pScene)
	{
		if (!pScene)
		{
			return ;
		}
		for (unsigned int i= 0 ; i <m_pScene.GetNum() ; i++)
		{
			if(pScene == m_pScene[i])
			{
				m_pScene.Erase(i);
			}
		}
	}

	inline unsigned int VSViewFamily::GetSceneNum()const
	{
		return m_pScene.GetNum();
	}
	class VSGRAPHIC_API VSWindowViewFamily : public VSViewFamily
	{
	public:
		enum 
		{
			VT_WINDOW_NORMAL,
			VT_WINDOW_MAX
		};
		VSWindowViewFamily(const VSString &ViewFamilyName,VSCamera * pCamera,VSPostEffectSetRPtr  pPostEffectSet,int iWindowID = -1,bool bDrawDebugInfo = true,bool bBeforePostDebugDraw = true);
		virtual ~VSWindowViewFamily();
		virtual void Draw(double dAppTime);
		virtual void CreateRenderTargetBuffer(unsigned int uiWidth,unsigned int uiHeight);

	protected:
		unsigned m_iWindowID;
		VSPEScreenQuadSceneRenderPtr  m_pScreenQuadRenderer;
	};

	class VSGRAPHIC_API VSCaptureViewFamily : public VSViewFamily, public VSObject
	{
	public:
		enum //ViewFamily Type
		{
			VT_CAPTURE_2D_CAPTURE_NORMAL,
			VT_CAPTURE_CUB_CAPTURE_NORMAL,
			VT_MAX
		};
		VSCaptureViewFamily(const VSString &ViewFamilyName,unsigned int uiWidth,unsigned int uiHeight,VSCamera * pCamera,VSPostEffectSetRPtr  pPostEffectSet,bool bDrawDebugInfo = true,bool bBeforePostDebugDraw = true);
		virtual ~VSCaptureViewFamily();
		virtual void Draw(double dAppTime);
		void SetSize(unsigned int uiWidth,unsigned int uiHeight);

		
	};

	class VSGRAPHIC_API VS3DCaptureViewFamily : public VSCaptureViewFamily
	{
	public:
		VS3DCaptureViewFamily(const VSString &ViewFamilyName,unsigned int uiWidth,unsigned int uiHeight,VSCamera * pCamera,VSPostEffectSetRPtr  pPostEffectSet,bool bDrawDebugInfo = true,bool bBeforePostDebugDraw = true);
		virtual ~VS3DCaptureViewFamily();
		virtual void Draw(double dAppTime);
		void SetSize(unsigned int uiWidth,unsigned int uiHeight);
		virtual void CreateRenderTargetBuffer(unsigned int uiWidth,unsigned int uiHeight);

	};
}
#endif